/**
 * 
 */
package easyservice.interpreter;

import junit.framework.TestCase;
import easyservice.EasyServiceException;
import easyservice.protocol.Command;
import easyservice.protocol.FaultCommand;
import easyservice.protocol.NotifyCommand;
import easyservice.protocol.RequestCommand;
import easyservice.protocol.ResponseCommand;

/**
 * This test class run unit tests for CommandInterpreter class.
 * 
 * @author Taciano Pinheiro
 *
 */
public class CommandInterpreterTest extends TestCase {

	public void testCommandRequest() {
		Command command = CommandInterpreter.interpret("# request getPrice prodId1");
		assertTrue(command.getClass().equals(RequestCommand.class));
		assertTrue(command.isSync());
		assertEquals(command.generatedString(), "# request getPrice prodId1");
	}
	
	public void testCommandResponse() {
		Command command = CommandInterpreter.interpret("# response 20,00");
		assertTrue(command.getClass().equals(ResponseCommand.class));
		assertTrue(command.isSync());
		assertEquals(command.generatedString(), "# response 20,00");
	}
	
	public void testCommandNotify() {
		Command command = CommandInterpreter.interpret("# notify lowPrice 1,00");
		assertTrue(command.getClass().equals(NotifyCommand.class));
		assertFalse(command.isSync());
		assertEquals(command.generatedString(), "# notify lowPrice 1,00");
	}
	
	public void testGetFault() {
		Command command = CommandInterpreter.interpret("# fault productNotExists theProductNotExists");
		assertTrue(command.getClass().equals(FaultCommand.class));
		assertTrue(command.isSync());
		assertEquals(command.generatedString(), "# fault productNotExists theProductNotExists");
	}

	public void testErroneousCommand() {
		try {
			CommandInterpreter.interpret("request getPrice prodId1");
		} catch (EasyServiceException e) {
			assertEquals("Command need start with '#'", e.getMessage());
		}
	}

}
